﻿@model Forest.Cat.Admin.Models.Resumes.ResumeShieldedListModel
@using Forest.Cat.Admin.Extensions;
@{
    ViewBag.Title = "隐私设置";
    Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}
<div class="savedsearch_manage_right">
    <div class="savedsearch_manage_right_title">
        @ViewBag.Title</div>
    <div class="savedsearch_manage_right_box">
        <p>
            <b>如果您不想让某些公司看到您公开的简历，那么请在这里屏蔽那些公司。</b></p>
        <br />
        <p>
            最多可以屏蔽20家公司</p>
        <br />
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    @Html.TextBoxFor(x => x.SearchName, new { @class = "long_input" })
                    <input value="搜索" id="SearchShieldedCompany" type="submit" />
                    
                    <div id="SearcheResultDialg" class="loginDialogCss" title="检索结果">
                    @using (Html.BeginForm("PopResumeShielded", "Resume", FormMethod.Post, new {@id="SaveForm" }))
                    {
                        <ul id="Resultlist" style="display: block;">
                            <li></li>
                        </ul>
                        @Html.Hidden("SaveIdList")
                    }
                    </div>
                    <script id="resultTemplate" type="text/html">

                        <div><a href="#">${CompanyName}</a></div>

                    </script>

                </td>
            </tr>
        </table>
        <br />
        <p>
            关键字必须5个字以上，一次搜索结果不超过20条记录！</p>
        <table cellpadding="0" cellspacing="0" class="rebook_tab" width="100%">
            <tr>
                <th>
                    <input type="checkbox" class="checkboxHeader" />
                </th>
                <th style="text-align: left;">
                    公司名称
                </th>
                <th>
                    操作
                </th>
            </tr>
            @foreach (var item in Model.ResumeShieldedModels)
            {
                <tr id=	'@item.Id'>
                    <td style="text-align: center; width: 30px;">
                        <input type="checkbox" class="checkboxItem" />
                    </td>
                    <td>
                        @item.CompanyName
                    </td>
                    <td style="text-align: center;">
                        @using (Html.BeginForm("ResumeShieldedDelete", "Resume", FormMethod.Post))
                        {
                            @Html.Hidden("DeleteId", item.Id.ToString())
                            <input type="submit" value="删除" onclick="return confirm('确定删除？');" />

                        }
                    </td>
                </tr>
            }
        </table>
        <div class="pages">
            <p>
                <a href="#">
                    @Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber")
                </a>
            </p>
            @using (Html.BeginForm("ResumeShieldedDeleteList", "Resume", FormMethod.Post))
            {
                @Html.Hidden("DeleteIdList", "")
                <input type="submit" value="删除所选记录" onclick="return GetSelectCheckBox();" />
            }
        </div>
    </div>
</div>
<script type="text/javascript" language="javascript">
    $(window).bind('load', function () {
        var cbHeader = $(".checkboxHeader");
        var cbRowItem = $(".checkboxItem");
        cbHeader.bind("click", function () {
            cbRowItem.each(function () { this.checked = cbHeader[0].checked; })
        });
        cbRowItem.bind("click", function () { if ($(this).checked == false) cbHeader[0].checked = false; });
    });

    function GetSelectCheckBox() {
        var ckList = $(".checkboxItem");
        var cknum = 0;
        var idList = new Array();
        ckList.each(function () {
            if (this.checked) {
                var id = $(this).parent().parent().attr("id");
                idList[cknum] = id;
                cknum = cknum + 1;
            }
        });

        if (cknum == 0) {
            alert("请至少选择一个checkbox");
            return false;
        }

        $("#DeleteIdList").val(idList);
        return confirm("确定删除？");



    }

    $(function () {
        $("#SearcheResultDialg").dialog({
            resizable: false,
            autoOpen: false,
            width: 700,
            height: 350,
            modal: true,
            close: function () { $("#Resultlist").children().remove(); },
            buttons: {
                "全选": function () {

                    var list = $("#Resultlist input[type=checkbox]");

                    $.each(list, function (index, el) {

                        $(el).attr("checked", true);

                    });

                },
                "保存": function () {

                    var checklist = $("#Resultlist input[type=checkbox]:checked");
                    var idlist = "";
                    $.each(checklist, function (index, el) {

                        idlist += $(el).attr("id") + ":" + $(el).attr("data") + ",";

                    });

                    $("#SaveIdList").val("");

                    $("#SaveIdList").val(idlist);

                    $("#SaveForm").submit();

                },
                "关闭": function () {
                    $("#Resultlist").children().remove();
                    $(this).dialog("close");
                }

            }
        });
    });

    function openDialog(id) {
        $('#' + id).dialog("open");
    }

    $("#SearchShieldedCompany").bind("click", function () {

        var str = $("#SearchName").val().trim();

        if (str.length==0) {
            alert("请输入检索关键字!");
            return;
        }

        if (str.length < 5) {
            alert("关键字必须5个字以上!");
            return;
        }
        //if (str.length)

        $.ajax({

            url: "ResumeShieldedSearch",

            type: "POST",

            data: { companname: str },

            dataType: "json",

            success: function (req) {

                //alert(req);
                //$("#resultTemplate").render(req).appendTo("#SearcheResultDialg");
                if (req.length==0) {

                    alert("未检索到数据，请重新输入关键字！");
                    return;
                
                }

                $.each(req, function (index, el) {

                    $("#Resultlist").append("<li style='float:left;width:300px;height:30px;line-height:30px;overflow:hidden;'><input style='margin-right:5px;' type='checkbox' id='" + el.Id + "' data='" + el.CompanyName + "' class='checkboxItem'/>" + el.CompanyName + "</li>")
                    //alert(el.Id + el.CompanyName);

                });
                //$("#SearcheResultDialg").html("<p>" + req + "</p>");
                openDialog("SearcheResultDialg");

            },
            error: function (msg) { alert(msg.responseText) }

        });

    });
</script>
